package com.itheima.day06_demo;

import java.util.Scanner;

public class Demo3_Judges_Scoring {
    public static void main(String[] args) {
//        目标：完成评委打分
        System.out.println("请输入评委打分的数量：");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println("getScore(n) = " + getScore(n));
    }
    public static double getScore(int n){
       //1.定义一个动态初始化数组，负责后期存入评委的打分
        int[] scores = new int[n];
        //2.遍历数组的每个位置，依次录入评委的分数
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第" + (i+1) + "个评委的打分：");
            scores[i] = sc.nextInt();
        }
        //3.从数组中计算出总分，找出最高分，最低分
        int sum = 0;
        int max = scores[0];
        int min = scores[0];

        //4.遍历数组找出这些数据
        for (int i = 0; i < scores.length; i++) {
            int score = scores[i];
            sum += score;
            if (score > max) {
                max = score;
            } else if (score < min) {
                min = score;
            }
        }
        //5.计算出平均分并返回
        return 1.0 * (sum - max - min) / (scores.length - 2);
    }
}
